const mongoose = require("mongoose");
const favoritesModel = mongoose.model("favorites");

module.exports = {
        add: async (data) => await favoritesModel.create(data),
        delete: async (_id) =>
                await favoritesModel.deleteOne({ _id }),
        getAll: async () => {
                // 获取所有订单信息，populate为链式调用方法
                return await favoritesModel.find().populate(`userId`).populate(`articleId`);
        },
        findId: async (userId) => {
                return await favoritesModel.find({ userId }).populate([
                        'userId', {
                                // 链式调用，进行多表查询
                                path: 'articleId',
                                populate: {
                                        path: 'userId'
                                }
                        }
                ]);
        }

}
